package com.steven.treatment_nurse.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.steven.treatment_nurse.R;
import com.steven.treatment_nurse.entity.HSBedEntity;

import java.util.List;

public class HSBedGridAdapter extends BaseAdapter {
    private List<HSBedEntity> hsList;
    private Context mContext;
    public HSBedGridAdapter(Context context,List<HSBedEntity> hsBedEntities) {
        this.mContext=context;
        this.hsList = hsBedEntities;
    }

    @Override
    public int getCount() {
        return hsList.size();
    }

    @Override
    public Object getItem(int position) {
        return hsList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;

        if (convertView == null) {
            viewHolder = new ViewHolder();
            // 获得容器
            convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_hs_bed, null);

            // 初始化组件
            viewHolder. tv_title = convertView.findViewById(R.id.tv_title);//床位
            viewHolder. tv_name = convertView.findViewById(R.id.tv_name);//姓名
            viewHolder. tv_sex = convertView.findViewById(R.id.tv_sex);//性别
            viewHolder. tv_age = convertView.findViewById(R.id.tv_age);//年龄
            viewHolder. tv_birth = convertView.findViewById(R.id.tv_birth);//出生日期
            viewHolder. tv_admissionTime = convertView.findViewById(R.id.tv_admissionTime);//入院时间
            viewHolder. tv_case = convertView.findViewById(R.id.tv_case);//病例
            // 给converHolder附加一个对象
            convertView.setTag(viewHolder);
        } else {
            // 取得converHolder附加的对象
            viewHolder = (ViewHolder) convertView.getTag();
        }
        HSBedEntity item=hsList.get(position);
        viewHolder.tv_title.setText(item.getHsBed());
        viewHolder.tv_name.setText(item.getName());
        viewHolder.tv_sex.setText(item.getSex());
        viewHolder.tv_age.setText(item.getAge());
        viewHolder.tv_birth.setText(item.getBirthDate());
        viewHolder.tv_admissionTime.setText(item.getAdmissionTime());
        viewHolder.tv_case.setText(item.getCaseHS());


        return convertView;
    }

    private class ViewHolder {
        TextView tv_title;//床位
        TextView tv_name;//姓名
        TextView tv_sex;//性别
        TextView tv_age;//年龄
        TextView tv_birth;//出生日期
        TextView tv_admissionTime;//入院时间
        TextView tv_case;//病例
    }
}
